package com.vitaf.cash.app.databinding

import org.json.JSONObject

/**
 * DataBinding工具类
 */
object DataBindingHelper {
    // 创建空模型
    fun createModel(): GenericObservableModel = GenericObservableModel()

    // 从 Map 创建
    fun fromMap(map: Map<String, Any?>): GenericObservableModel {
        return GenericObservableModel().apply {
            setAll(map)
        }
    }

    // 从 JSONObject 创建（如果需要）
    fun fromJson(json: JSONObject): GenericObservableModel {
        return GenericObservableModel().apply {
            val keys = json.keys()
            while (keys.hasNext()) {
                val key = keys.next()
                set(key, json.get(key))
            }
        }
    }

    // 从键值对创建
    fun fromVarargs(vararg pairs: Pair<String, Any?>): GenericObservableModel {
        return GenericObservableModel().apply {
            setAll(mapOf(*pairs))
        }
    }
}